package com.bite.springblog.controller;

import com.bite.springblog.pojo.request.UserLoginRequest;
import com.bite.springblog.pojo.response.Result;
import com.bite.springblog.pojo.response.UserInfoResponse;
import com.bite.springblog.pojo.response.UserLoginResponse;
import com.bite.springblog.service.UserService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource(name = "userServiceImpl")
    private UserService userService;

    @RequestMapping("/login")
    public Result userLogin(@RequestBody @Validated UserLoginRequest userLoginRequest){
        UserLoginResponse userLoginResponse = userService.userLogin(userLoginRequest);
        return Result.success(userLoginResponse);
    }

    @RequestMapping("/getuserinfo")
    public UserInfoResponse getUserInfo(@NotNull String userId){
        UserInfoResponse userInfoResponse = userService.getUserInfo(userId);
        return userInfoResponse;
    }

    @RequestMapping("/getauthorinfo")
    public UserInfoResponse getAuthorInfo(@NotNull String blogId){
        UserInfoResponse userInfoResponse = userService.getAuthorInfo(blogId);
        return userInfoResponse;
    }
}
